package com.apidocs.code.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * IndexController
 *
 * @author <a href="morse.jiang@foxmail.com">JiangWen</a>
 * @version 1.0.0, 2018/6/4 0004 11:44
 */
@Controller
public class IndexController {
  @Value("${spring.datasource.driver-class-name}")
  private String driverClassName;
  @Value("${spring.datasource.name}")
  private String dbName;
  @Value("${spring.datasource.url}")
  private String dbUrl;
  @Value("${spring.datasource.username}")
  private String dbUserName;
  @Value("${spring.datasource.password}")
  private String dbPassword;
  @Autowired
  private TextEncryptor textEncryptor;

  @GetMapping("/")
  public String index(ModelMap modelMap){
    modelMap.put("driverClassName", driverClassName);
    modelMap.put("dbName", dbName);
    modelMap.put("dbUrl", dbUrl);
    modelMap.put("dbUserName", "{cipher}" + textEncryptor.encrypt(dbUserName));
    modelMap.put("dbPassword", "{cipher}" + textEncryptor.encrypt(dbPassword));
    return "index";
  }

}
